package com.odobenus.client.configurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.odobenus.client.hock.StartListener;
import com.odobenus.client.processor.AplolloBeanPostProcessor;
import com.odobenus.client.processor.OdobenusClientBeanPostProcessor;
import com.odobenus.client.properties.OdobenusProperties;
import com.odobenus.client.zk.ZooKeeperServiceRegistry;


@Configuration
@ConditionalOnWebApplication
@EnableConfigurationProperties(OdobenusProperties.class)
public class OdobenusAutoConfigurer {
	@Autowired
	private OdobenusProperties odobenusProperties;
	
	@Bean
	public ZooKeeperServiceRegistry zooKeeperServiceRegistry() {
		return new ZooKeeperServiceRegistry(odobenusProperties.getZookeeperAddress());
	}
	
	@Bean
	public StartListener startListener() {
		return new StartListener(zooKeeperServiceRegistry(),odobenusProperties);
	}
	
	@Bean
	public OdobenusClientBeanPostProcessor odobenusClientBeanPostProcessor() {
		OdobenusClientBeanPostProcessor odobenusClientBeanPostProcessor = new OdobenusClientBeanPostProcessor();
		odobenusClientBeanPostProcessor.setOdobenusProperties(odobenusProperties);
		return odobenusClientBeanPostProcessor;
	}
	
	
	@Bean
	public AplolloBeanPostProcessor aplolloBeanPostProcessor() {
		return new AplolloBeanPostProcessor();
	}
}